﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using cart.utils;
using cart.model;

namespace cart.dao
{
    public class userDao
    {
        public userModel getUserByUserID(string userID)
        {
            string SELECT_USER_BY_USERID = "select * from [user] where userID='"+userID+"'";
            userModel um = new userModel();
            SqlConnection conn = DB.getSqlConnection();
            DB.connectionOpen(conn);

            SqlCommand cmd = new SqlCommand(SELECT_USER_BY_USERID, conn);
            SqlDataReader sdr = cmd.ExecuteReader();

            if (sdr.Read())
            {
                um.userID = sdr.GetString(0).Trim();
                //um.password = sdr.GetString(1);
                um.userName = (sdr.IsDBNull(2)) ? null : sdr.GetString(2).Trim();
                um.userAddr = (sdr.IsDBNull(3)) ? null : sdr.GetString(3).Trim() ;
                um.userPhone = (sdr.IsDBNull(4)) ? null : sdr.GetString(4).Trim();
            }

            DB.connectionClose(conn);
            return um;

        }
    }
}
